<script setup>
import { inject, ref } from "vue";
import { goPage } from "@/utils/newpage";
import { formatPrice } from "@/utils/formatPrice";
import { onLoad, onReachBottom } from "@dcloudio/uni-app";
import { countApi, bonusApi } from "@/services/team";

onLoad(() => {
  countApiFun();
  bonusApiFun();
});

// 前往我的vip
const goVip = () => {
  uni.navigateTo({
    url: "/pages/team/teamlist/index",
  });
};

// // 前往赠送VIP名额
const goQuotaVoucher = () => {
  uni.navigateTo({
    url: "/pages/team/shopkeeper/quotaVoucher",
  });
};

const countData = ref({});
const bonusData = ref({});

const countApiFun = async () => {
  try {
    let res = await countApi();
    countData.value = res.data;
  } catch (e) {
    uni.showToast({
      title: e.info,
      icon: "none",
    });
  }
};

const bonusApiFun = async () => {
  // try {
  //   let res = await bonusApi();
  //   bonusData.value = res.data;
  // } catch (e) {
  //   uni.showToast({
  //     title: e.info,
  //     icon: "none",
  //   });
  // }
};

const showPopup = ref(false);

const close = () => {
  showPopup.value = false;
};

const gobonus = () => {
  uni.navigateTo({
    url: "/pages/team/shopkeeper/bonus",
  });
};
</script>
<template>
  <view class="myWork">
    <view class="myWork-card">
      <view class="top">
        <view class="top-left">
          <image src="@/pages/team/static/user-icon.png" mode="widthFix" />
          <text>团队管理</text>
        </view>
      </view>
      <view class="content" @click="goQuotaVoucher">
        <view class="content-left">
          <text class="content-left-title">赠送升级券名额（人）</text>
          <text class="content-left-num">{{ countData.total }}</text>
          <view class="content-left-footer">
            <view class="content-left-footer-text"
              >已使用：<text>{{ countData.count_yes }}</text
              >未使用：<text>{{ countData.count_no }}</text></view
            >
          </view>
        </view>
        <view class="content-right">
          <image src="@/pages/team/static/right-icon.png" mode="widthFix" />
        </view>
      </view>
      <view class="content" @click="goVip">
        <view class="content-left">
          <text class="content-left-title">我的VIP（人）</text>
          <text class="content-left-num">{{ countData.vip_total }}</text>
        </view>
        <view class="content-right1">
          <image src="@/pages/team/static/right-icon.png" mode="widthFix" />
        </view>
      </view>
    </view>
    <!-- <view class="myWork-card">
      <view class="top">
        <view class="top-left">
          <image src="@/pages/team/static/money-icon.png" mode="widthFix" />
          <text>分红奖池</text>
        </view>
        <view class="top-right">
          <text>更新于{{ bonusData.time }}</text>
        </view>
      </view>
      <view class="content">
        <view class="content-left">
          <view class="content-left-title">
            <view class="left-item">
              <text>本月待发奖池总金额(元)</text>
              <view class="content-left-title-img">
                <uni-tooltip
                  class="item"
                  content="本期平台内待分红奖池总全额"
                  placement="top"
                >
                  <image src="@/pages/team/static/icon.png" mode="widthFix" />
                </uni-tooltip>
              </view>
            </view>
            <view class="right-item" @click="gobonus">
              <text>本期参与分红</text>
              <view class="content-left-title-img">
                <image
                  src="@/pages/team/static/right-red.png"
                  mode="widthFix"
                />
              </view>
            </view>
          </view>
          <text class="content-num">
            <text>￥{{ bonusData.total_bonus }}</text>
          </text>
          <view class="content-left-footer">
            <view class="content-left-footer-text"
              >下次分红时间：<text>{{ bonusData.bonus_time }}</text></view
            >
          </view>
        </view>
      </view>

      <view class="content">
        <view class="content-left">
          <view class="content-left-title">
            <view class="left-item">
              <text>平台本期业绩总额(元)</text>
              <view class="content-left-title-img">
                <uni-tooltip
                  class="item"
                  content="平台本期所有经销商新增的业绩总金额，用于加权分红计算"
                  placement="top"
                >
                  <image src="@/pages/team/static/icon.png" mode="widthFix" />
                </uni-tooltip>
              </view>
            </view>
            <view class="right-item1">
              <text>我本期的业绩(元)</text>
              <view class="content-left-title-img">
                <uni-tooltip
                  class="item"
                  content="我在本期内的新增业绩，计算直推和间推两级业绩金额占比"
                  placement="left"
                >
                  <image src="@/pages/team/static/icon.png" mode="widthFix" />
                </uni-tooltip>
              </view>
            </view>
          </view>

          <view class="content-footer-num">
            <view class="content-left-num">
              <text
                >￥{{
                  bonusData.total_performance ? bonusData.total_performance : 0
                }}</text
              >
            </view>
            <view class="content-right-num">
              <text
                >￥{{
                  bonusData.my_performance ? bonusData.my_performance : 0
                }}</text
              >
            </view>
          </view>
        </view>
      </view>

      <view class="myWork-card-footer" @click="showPopup = true"
        ><text>查看分红计算规则</text>
        <image src="@/pages/team/static/right-icon.png" mode="widthFix"
      /></view>
    </view> -->
  </view>

  <u-popup
    :show="showPopup"
    mode="center"
    round="10"
    @close="close"
    @open="open"
  >
    <view class="card-rules">
      <view class="popup-content-title">分红计算规则</view>
      <view class="popup-content-item"
        >1、20%分给每个所有经销商，根据经销商等级按照联盟店10%、认证店20%、形象店30%、旗航店40%，平均分配给各等级内的所有经销商（不分给vip和用户）。
      </view>
      <view class="popup-content-item"
        >2、80%资金按当月新增业绩（含复购）加权分红，新增业绩额只计算向下两级。
      </view>
      <view class="popup-content-box" @click="showPopup = false">我知道了</view>
    </view>
  </u-popup>
</template>

<style lang="scss" scoped>
@import "./myWork.scss";
</style>
